
import 'package:flutter/material.dart';
import 'package:flutter_deer/account/models/account_summary_entity.dart';
import 'package:flutter_deer/index/models/football_ratio_entity.dart';
import 'package:flutter_deer/util/other_utils.dart';
import 'package:flutter_deer/widgets/state_layout.dart';

class GameUnstartProvider extends ChangeNotifier {

  StateType? _gameStateType = StateType.loading;
  StateType? get gameStateType => _gameStateType;
  bool? _groupLoading = true;
  bool? _gameLoading = true;
  List<FootballRatioGroupEntity>? _groupList;
  List<FootballGameUnstartEntity>? _gameList;

  List<FootballRatioGroupEntity>? get groupList => _groupList;
  List<FootballGameUnstartEntity>? get gameList => _gameList;
  bool? get groupLoading => _groupLoading;
  bool? get gameLoading => _gameLoading;
  bool? _giveScoreChecked = false;
  double? _residueGiveScore = 0.0;
  bool? get giveScoreChecked => _giveScoreChecked;
  double? get residueGiveScore => _residueGiveScore;
  FootballGameUnstartEntity? _currentEntity;
  FootballGameUnstartEntity? get currentEntity => _currentEntity;
  double? get orderAmount => _orderAmountStr!=''?double.tryParse(_orderAmountStr.nullSafe):0;
  double? get willPrizeAmount => _currentEntity!.ratio!.odds!*orderAmount!;

  StateType? _accountSummaryStateType = StateType.loading;
  AccountSummaryEntity? _accountSummaryData;
  StateType? get accountSummaryStateType => _accountSummaryStateType;
  AccountSummaryEntity? get accountSummaryData => _accountSummaryData;
  String? _orderAmountStr = '';
  String? get orderAmountStr => _orderAmountStr;

  void setGameGroups(List<FootballRatioGroupEntity>? list){
    this._groupList = list;
    this._groupLoading = false;
    notifyListeners();
  }

  void setRatios(List<FootballGameUnstartEntity>? list){
    this._gameList = list;
    this._gameLoading = false;
    _gameStateType = StateType.game;
    notifyListeners();
  }

  void setGiveScoreChecked(bool? val) {
    _giveScoreChecked = val;
    notifyListeners();
  }

  void setResidueGiveScore(double? val) {
    _residueGiveScore = val;
    notifyListeners();
  }

  void setAccountSummary(AccountSummaryEntity? entity) {
    this._accountSummaryData = entity;
    this._accountSummaryStateType = StateType.empty;
    notifyListeners();
  }

  void setCurrentEntity(FootballGameUnstartEntity entity) {
    _currentEntity = entity;
    notifyListeners();
  }

  Future<dynamic> appendOrderAmountStr(String value) async {
    _orderAmountStr = _orderAmountStr.nullSafe + value;
    notifyListeners();
  }

  Future<dynamic> deleteOrderAmountStrByLast() async {
    if(_orderAmountStr.nullSafe.length>0) {
      _orderAmountStr = _orderAmountStr.nullSafe
          .substring(0, _orderAmountStr.nullSafe.length - 1)
          .nullSafe;
    }else{
      _orderAmountStr = '';
    }
    notifyListeners();
  }

  Future<dynamic> resetOrderAmmountStr() async {
    _orderAmountStr = '';
    notifyListeners();
  }

  void saveBetting(){

  }

}